package controllers

import (
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/validation"
)

// Operations about Users
type CommonController struct {
	beego.Controller
}

func init() {
	validation.SetDefaultMessage(map[string]string{
		"Required":     "不能为空",
		"Min":          "不能小于%d",
		"Max":          "不能大于%d",
		"Range":        "必须在%d-%d之间",
		"MinSize":      "最小长度%d",
		"MaxSize":      "最大长度%d",
		"Length":       "长度只能为%d",
		"Alpha":        "仅限字母",
		"Numeric":      "仅限字母",
		"AlphaNumeric": "仅限数字和字母",
		"Match":        "不符合规则",
		"NoMatch":      "不符合规则",
		"AlphaDash":    "仅限数字、字母和下划线",
		"Email":        "貌似不正确哦",
		"IP":           "貌似不正确哦",
		"Base64":       "必须是base64",
		"Mobile":       "貌似不正确哦",
		"Tel":          "貌似不正确哦",
		"Phone":        "貌似不正确哦",
		"ZipCode":      "Must be valid zipcode",
	})
}

func (u *CommonController) Success(data interface{}) {
	u.Data["json"] = map[string]interface{}{"code": 200,"data": data,"msg": "success"}
	u.ServeJSON()
}

func (u *CommonController) Failed(code int,msg string,data interface{}) {
	u.Data["json"] = map[string]interface{}{"code": code,"data": data,"msg": msg}
	u.ServeJSON()
}

